﻿using CallCenter.Data.Base;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CallCenter.Data.BizUtilities
{
    public class ScratchUtility : BaseUtility
    {
        public ScratchUtility(DataManager manager)
            :base(manager)
        { }

        public DataTable GetScratch()
        {
            string sql = "SELECT cs.id as id, cl.id as clId, cs.firstName+' '+ cs.lastName as Name, cs.firstName, cs.lastName, " +
                " cs.businessPhone as Phone, cs.companyId, cs.email, cp.name as company, ct.description as contactType, " +
                " ct.id as contactTypeId, cm.description as cmd, cm.id as cmId, s.description as status, s.id statusId, " +
                "CONVERT(date, cl.callDate) as callDate from ccContacts cs " +
                " LEFT JOIN ContactScratch cl on cl.ContactId = cs.id " +
                " LEFT JOIN ddlCompany cp on cp.id = cs.companyId " +
                " LEFT JOIN ddlContactTypes ct on ct.id= cs.contactType " +
                " LEFT JOIN ddlCommunicationMedium cm ON cl.CommunicationMedium= cm.id " +
                " LEFT JOIN ddlStatus s ON s.id = cl.Status";

            return this.Factory.ExecuteTable(sql);

        }

        public DataTable GetAll()
        {
            string sql = " SELECT cs.id, cs.firstName+' '+ cs.lastName as Name, " +
                " cs.businessPhone as Phone, cs.email, " +
                " ct.description as ConTyp, cm.description as cmd, s.description as statusDes from ccContacts cs " +
                " INNER JOIN ContactScratch cl on cl.ContactId = cs.id " +
                " INNER JOIN ddlContactTypes ct on ct.id= cs.contactType " +
                " INNER JOIN ddlCommunicationMedium cm ON cl.CommunicationMedium= cm.id " +
                " INNER JOIN ddlStatus s ON s.id = cl.Status ORDER BY cl.date DESC";

            return this.Factory.ExecuteTable(sql);

        }

        public DataTable GetHistory(int userId)
        {
            string sql = " SELECT cl.*, cl.id as clid, cm.description as commVia, " +
                                    " cs.Id, cs.FirstName+' '+cs.LastName as Name, s.description as status, " +
                                    " c.name as company, p.product " +
                                    " FROM ScratchCallLogs cl  " +
                                    " LEFT JOIN ddlCommunicationMedium cm ON  cm.id = cl.via " +
                                    " LEFT JOIN ccContacts cs ON cs.Id = cl.ContactId " +
                                    " LEFT JOIN ContactScratch ch ON ch.id = cl.ContactId" +
                                    " LEFT JOIN ddlProducts p ON p.id = cl.productId" +
                                    " LEFT JOIN ddlcompany c ON c.id = cl.companyId" +
                                    " LEFT JOIN ddlStatus s ON s.id = cl.statusId" +
                                    " WHERE s.id <> 1 AND cl.userId = " + userId + " OR cl.visibleToOthers = 'true' " + " ORDER BY cl.date DESC"; ;

            return this.Factory.ExecuteTable(sql);

        }
        public DataTable GetHistory(int contId, int userId)
        {
            string sql = " SELECT cl.id as clid, cm.description as via, " +
                                    " cs.Id, cs.FirstName+' '+cs.LastName as Name, cl.notes, cl.date, " +
                                    " cl.inOrOut as inOrOut, co.name as company " +
                                    " , p.product as product, cl.companyid,cl.productId " +
                                    " FROM ScratchCallLogs cl " +
                                    " INNER JOIN ddlCommunicationMedium cm ON  cm.id = cl.via " +
                                    " INNER JOIN ccContacts cs ON cs.Id = cl.ContactId " +
                                    //" INNER JOIN ContactScratch ch ON ch.id = cl.contactScratchId "+
                                    " LEFT JOIN ddlCompany co on co.id = cl.companyid " +
                                    " LEFT JOIN ddlProducts p on p.id = cl.productid " +
                                    " WHERE cs.Id =" + contId + " AND cl.userId = " + userId + " ORDER BY cl.Date DESC";

            return this.Factory.ExecuteTable(sql);

        }

        public int InsertComCont( int companyId, int contactId)
        {
            int nRtn = -1;
            string sql = "INSERT INTO ddlCompanyContacts " +
                " (companyId, contactId) " +
                " VALUES (@companyId, @contactId) ";
            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@companyId", SqlDbType.Int, 10, companyId);
                this.Factory.AddParameter(cmd, "@contactId", SqlDbType.Int, 10, contactId);
               // this.Factory.AddParameter(cmd, "@Id", SqlDbType.Int, 10, contactId);
                this.Factory.ExecuteNonQuery(cmd);
            }

            //cmdInsert.Parameters.Add("@Id", SqlDbType.Int);
            //cmdInsert.Parameters["@id"].Direction = ParameterDirection.Output;

            return nRtn; //retruning the data stored in the table
        }

        public int InsertToCallLog(int userId, string caller, string phone, int contactId, int companyId,  int productId,  DateTime date, int via,string notes, string inOrOut, int statusId, bool visibleToOthers, DateTime updateDate )
        {
            int nRtn = -1;
           string sql = "INSERT INTO ScratchCallLogs " +
                " ( userId,caller,phone,contactId, companyId,productId, date, via, notes, inOrOut,statusId,visibleToOthers,updateDate ) " +
                " VALUES (@userId,@caller,@phone,@contactId, @companyId,@productId,@date, @via, @notes, @inOrOut,@statusId,@visibleToOthers,@updateDate) " +
                " SELECT @ID =@@IDENTITY";

            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@userId", SqlDbType.Int, 10, userId);
                this.Factory.AddParameter(cmd, "@caller", SqlDbType.NVarChar, 100, caller);
                this.Factory.AddParameter(cmd, "@phone", SqlDbType.NVarChar, 100, phone);
                this.Factory.AddParameter(cmd, "@companyId", SqlDbType.Int, 10, companyId);
                this.Factory.AddParameter(cmd, "@contactId", SqlDbType.Int, 10, contactId);
                this.Factory.AddParameter(cmd, "@date", SqlDbType.DateTime,0, date);
                this.Factory.AddParameter(cmd, "@via", SqlDbType.Int, 10, via);
                this.Factory.AddParameter(cmd, "@notes", SqlDbType.NVarChar, 1000, notes);
                this.Factory.AddParameter(cmd, "@inOrOut", SqlDbType.NVarChar, 7, inOrOut);
                this.Factory.AddParameter(cmd, "@productId", SqlDbType.Int, 10, productId);
                this.Factory.AddParameter(cmd, "@statusId", SqlDbType.Int, 10, statusId);
                this.Factory.AddParameter(cmd, "@visibleToOthers", SqlDbType.Bit,0, visibleToOthers);
                this.Factory.AddParameter(cmd, "@updateDate", SqlDbType.DateTime,0, updateDate);
                this.Factory.ExecuteNonQuery(cmd);
            }
            //cmdInsert.Parameters.Add("@Id", SqlDbType.Int, 10);
            //  cmdInsert.Parameters["@id"].Direction = ParameterDirection.Output;

            return nRtn; //retruning the data stored in the table
        }

        public int UpdateToCallLog( int id, int userId, string caller, string phone, int contactId, int companyId, int productId, int via, string notes, string inOrOut, int statusId, bool visibleToOthers, DateTime updateDate)
        {
            int nRtn = -1;
           string sql = "UPDATE ScratchCallLogs " +
                " SET userId=@userId,caller=@caller,phone=@phone,contactId=@contactId, companyId=@companyId," +
                " productId=@productId, via=@via, notes=@notes, inOrOut=@inOrOut, statusId=@statusId," +
                "visibleToOthers=@visibleToOthers,updateDate=@updateDate " +
                " WHERE id =@id ";
            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@userId", SqlDbType.Int, 10, userId);
                this.Factory.AddParameter(cmd, "@caller", SqlDbType.NVarChar, 100, caller);
                this.Factory.AddParameter(cmd, "@phone", SqlDbType.NVarChar, 100, phone);
                this.Factory.AddParameter(cmd, "@companyId", SqlDbType.Int, 10, companyId);
                this.Factory.AddParameter(cmd, "@contactId", SqlDbType.Int, 10, contactId);
                this.Factory.AddParameter(cmd, "@via", SqlDbType.Int, 10, via);
                this.Factory.AddParameter(cmd, "@notes", SqlDbType.NVarChar, 1000, notes);
                this.Factory.AddParameter(cmd, "@inOrOut", SqlDbType.NVarChar, 7, inOrOut);
                this.Factory.AddParameter(cmd, "@productId", SqlDbType.Int, 10, productId);
                this.Factory.AddParameter(cmd, "@statusId", SqlDbType.Int, 10, statusId);
                this.Factory.AddParameter(cmd, "@visibleToOthers", SqlDbType.Bit, 0, visibleToOthers);
                this.Factory.AddParameter(cmd, "@updateDate", SqlDbType.DateTime, 0, updateDate);
                // this.Factory.AddParameter(cmd, "@Id", SqlDbType.Int, 10,id);
                this.Factory.ExecuteNonQuery(cmd);

            }

            //cmdUpdate.Parameters.Add("@Id", SqlDbType.Int, 10);
            //cmdUpdate.Parameters["@id"].Value = id;
                     
            return nRtn; //retruning the data stored in the table
        }

        public int UpdateScratchId(int commId, int id)
        {
            int nRtn = -1;
          string sql = "UPDATE ScratchCallLogs " +
                " SET commId=@commId where id = @id ";

            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@commId", SqlDbType.Int,10,commId);
               // this.Factory.AddParameter(cmd, "@Id", SqlDbType.Int, 10,id);
                this.Factory.ExecuteNonQuery(cmd);
            }
           
            //cmdUpdate.Parameters.Add("@Id", SqlDbType.Int, 10);
            //cmdUpdate.Parameters["@id"].Value = id;

         
            return nRtn; //retruning the data stored in the table
        }

        public int Insert( int contactId, int ComMed, DateTime callDate, int status, string notes, bool m2Cont)
        {
            int nRtn = -1;
            string sql= "INSERT INTO ContactScratch " +
                " (contactId, CommunicationMedium, " +
                " CallDate, Status, Notes, m2c) " +
                " VALUES (@contactId, @CommunicationMedium, @CallDate, @Status, @Notes, @m2c) " +
                " SELECT @ID =@@IDENTITY";
            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@CommunicationMedium", SqlDbType.Int, 10, ComMed);
                this.Factory.AddParameter(cmd, "@CallDate", SqlDbType.SmallDateTime, 0, callDate);
                this.Factory.AddParameter(cmd, "@Status", SqlDbType.Int, 10, status);
                this.Factory.AddParameter(cmd, "@m2c", SqlDbType.Bit, 0, m2Cont);
                this.Factory.AddParameter(cmd, "@notes", SqlDbType.NVarChar, 1000, notes);
                this.Factory.ExecuteNonQuery(cmd);
            }

            //cmdInsert.Parameters.Add("@Id", SqlDbType.Int, 10);

            //cmdInsert.Parameters["@id"].Direction = ParameterDirection.Output;

            return nRtn; //retruning the data stored in the table
        }

        public int Update( int id, int ComMed, DateTime callDate,int status,  string notes, bool m2Cont )
        {
            int nRtn = -1;
            string sql = "UPDATE ContactScratch " +
                " SET CommunicationMedium=@CommunicationMedium, " +
                " CallDate=@CallDate, Status=@Status, Notes=@Notes, m2c=@m2c" +
                " WHERE id=@id ";
            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@CommunicationMedium", SqlDbType.Int, 10,ComMed);
                this.Factory.AddParameter(cmd, "@CallDate", SqlDbType.SmallDateTime,0,callDate);
                this.Factory.AddParameter(cmd, "@Status", SqlDbType.Int, 10,status);
                this.Factory.AddParameter(cmd, "@m2c", SqlDbType.Bit,0,m2Cont);
                this.Factory.AddParameter(cmd, "@notes", SqlDbType.NVarChar, 1000, notes);
                this.Factory.ExecuteNonQuery(cmd);
            }

            //cmdUpdate.Parameters.Add("@Id", SqlDbType.Int, 10);

            //cmdUpdate.Parameters["@id"].Value = id;

            return nRtn; //retruning the data stored in the table
        }

        public int UpdateToContact( int id,string LName,string FName,int conType,int companyId, DateTime callDate,int status,string notes,  string phone,string email, bool m2Cont)
        {
            int nRtn = -1;
           string sql = " UPDATE ccContacts " +
                " SET FirstName=@FirstName, LastName=@LastName, ContactType=@ContactTypes, " +
                " companyId=@companyId, enteredDate=@CallDate, businessPhone=@businessPhone, " +
                " Email=@Email, notes=@notes, visibleToOthers=@visibleToOthers WHERE id=@id ";

            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@FirstName", SqlDbType.NVarChar, 50, FName);
                this.Factory.AddParameter(cmd, "@LastName", SqlDbType.NVarChar, 50, LName);
                this.Factory.AddParameter(cmd, "@ContactType", SqlDbType.Int, 10, conType);
                this.Factory.AddParameter(cmd, "@companyId", SqlDbType.Int, 10, companyId);
                this.Factory.AddParameter(cmd, "@callDate", SqlDbType.Date, 0, callDate);
                this.Factory.AddParameter(cmd, "@visibleToOthers", SqlDbType.Bit, 0, status);
                this.Factory.AddParameter(cmd, "@businessPhone", SqlDbType.NVarChar, 15, phone);
                this.Factory.AddParameter(cmd, "@email", SqlDbType.NVarChar, 50, email);
                this.Factory.AddParameter(cmd, "@notes", SqlDbType.NVarChar, 100, notes);
                this.Factory.ExecuteNonQuery(cmd);
            }

            //Ask abhishek
            //cmdInsert.Parameters.Add("@Id", SqlDbType.Int);
            //cmdInsert.Parameters["@id"].Value = id;

            return nRtn; //retruning the data stored in the table
        }

        public int UpdateToContact( int id,bool visibleToOthers)
        {
            int nRtn = -1;
            string sql = " UPDATE ccContacts " + " SET visibleToOthers=@visibleToOthers WHERE id=@id ";

            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@visibleToOthers", SqlDbType.Bit, 50, visibleToOthers);
               // this.Factory.AddParameter(cmd, "@Id", SqlDbType.Int, 10, id);
                this.Factory.ExecuteNonQuery(cmd);
            }

            //cmdInsert.Parameters.Add("@Id", SqlDbType.Int);

            //cmdInsert.Parameters["@id"].Value = id;

            return nRtn; //retruning the data stored in the table
        }

        public int AddToContact( string LName,string FName, int contactType, int companyId,DateTime callDate, string phone, string email,bool m2Cont  )
        {
            int nRtn = -1;
           
          string sql = "INSERT INTO ccContacts " +
                " (FirstName, LastName, " +
                " contactType, businessPhone, companyId, Email, visibleToOthers) " +
                " VALUES (@FirstName, @LastName, @ContactType, @businessPhone, @companyId, @Email, @visibleToOthers) " +
                " SELECT @ID =@@IDENTITY";
            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@FirstName", SqlDbType.NVarChar, 50, FName);
                this.Factory.AddParameter(cmd, "@LastName", SqlDbType.NVarChar, 50, LName);
                this.Factory.AddParameter(cmd, "@ContactType", SqlDbType.Int, 10, contactType);
                this.Factory.AddParameter(cmd, "@companyId", SqlDbType.Int, 10, companyId);
                this.Factory.AddParameter(cmd, "@callDate", SqlDbType.Date, 0, callDate);
                //no parameter.
                this.Factory.AddParameter(cmd, "@visibleToOthers", SqlDbType.Bit, 0, null);
                this.Factory.AddParameter(cmd, "@businessPhone", SqlDbType.NVarChar, 15,phone );
                this.Factory.AddParameter(cmd, "@email", SqlDbType.NVarChar, 50, email);
                this.Factory.ExecuteNonQuery(cmd);
            }

            
            //Ask 
            //cmdInsert.Parameters.Add("@Id", SqlDbType.Int);

          //  cmdInsert.Parameters["@id"].Direction = ParameterDirection.Output;

            return nRtn; //retruning the data stored in the table
        }

        public void Delete(int id)
        {
            string sql = " DELETE FROM ScratchCallLogs WHERE ID = @ID ";
            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@ID", SqlDbType.Int, 10, id);
                this.Factory.ExecuteNonQuery(cmd);
            }
        }
      public int InsertScratch( string lastname,string firstname, int contactTypes, DateTime callDate, string status, string phone, string email,string communicationMedium, string notes )
        {
            int nRtn = -1;
           string sql  = "INSERT INTO contactScratch" +
                "(LastName, FirstName, ContactTypes, phone, callDate, email, communicationMedium, Status, Notes) " +
            "VALUES(@LastName, @FirstName, @ContactTypes, @phone, @callDate, @email, @communicationMedium, @Status, @notes)" +
            "SELECT @ID =@@IDENTITY";
            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@FirstName", SqlDbType.NVarChar, 50, firstname);
                this.Factory.AddParameter(cmd, "@LastName", SqlDbType.NVarChar, 50, lastname);
                this.Factory.AddParameter(cmd, "@Email", SqlDbType.NVarChar, 50, email);
                this.Factory.AddParameter(cmd, "@Phone", SqlDbType.NVarChar, 50, phone);
                this.Factory.AddParameter(cmd, "@contactTypes", SqlDbType.NVarChar, 10, contactTypes);
                this.Factory.AddParameter(cmd, "@communicationMedium", SqlDbType.NVarChar, 10, communicationMedium);
                this.Factory.AddParameter(cmd, "@notes", SqlDbType.VarChar, 1000, notes);
                this.Factory.AddParameter(cmd, "@Status", SqlDbType.VarChar, 100, status);
                this.Factory.AddParameter(cmd, "@callDate", SqlDbType.Date, 10, callDate);
                // this.Factory.AddParameter(cmd, "@Id", SqlDbType.Int, 10,id);
                this.Factory.ExecuteNonQuery(cmd);
            }
          
            return nRtn; //retruning the data stored in the table
        }

        public int UpdateScratch(int id,string lastname, string firstname,string contactTypes, string status, string phone, string email, string communicationMedium, string notes )
        {
            int nRtn = -1;
           string sql = "UPDATE contactScratch SET " +
                " LastName=@LastName, FirstName=@FirstName, ContactTypes=@ContactTypes, " +
                " phone=@phone, email=@email, communicationMedium=@communicationMedium, " +
                " Status=@Status, Note=@Note WHERE id=@id ";
            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@FirstName", SqlDbType.NVarChar, 50, firstname);
                this.Factory.AddParameter(cmd, "@LastName", SqlDbType.NVarChar, 50, lastname);
                this.Factory.AddParameter(cmd, "@Email", SqlDbType.NVarChar, 50, email);
                this.Factory.AddParameter(cmd, "@Phone", SqlDbType.NVarChar, 50, phone);
                this.Factory.AddParameter(cmd, "@contactTypes", SqlDbType.NVarChar, 10, contactTypes);
                this.Factory.AddParameter(cmd, "@communicationMedium", SqlDbType.NVarChar, 10, communicationMedium);
                this.Factory.AddParameter(cmd, "@notes", SqlDbType.VarChar, 1000, notes);
                this.Factory.AddParameter(cmd, "@Status", SqlDbType.VarChar, 100, status);
                // this.Factory.AddParameter(cmd, "@Id", SqlDbType.Int, 10,id);
                this.Factory.ExecuteNonQuery(cmd);
            }      
            return nRtn; //retruning the data stored in the table
        }

        //public DataTable GetAll()
        //{
        //    string sql = "SELECT * from ccCallsLog";
        //    return this.Factory.ExecuteTable(sql);
                    
        //}

        public DataTable GetAllScratch()
        {
           string sql = "SELECT * from ContactScratch";
           return this.Factory.ExecuteTable(sql);
        }

        public DataTable getMinimum()
        {
            string sql = "SELECT cl.Id, cc.firstName+' '+ cc.lastName as Name, cl.callDate as Date, cl.notes, followupDate, " +
                " cl.serviceCall, cl.billable, cl.notes, cl.VisibleToOther, cp.name as Company, cm.description as Via FROM ccCallsLog cl " +
                " INNER JOIN ddlCompany cp ON cp.id= cl.companyId " +
                " Inner JOIN ccContacts cc ON cc.id = cl.contactId " +
                " Inner Join ddlProductRequests pr ON pr.Id = cl.projectId " +
                " INNER JOIN ddlCommunicationMedium cm ON cm.id = cl.communicationId ";
            return this.Factory.ExecuteTable(sql);
        }
        public DataTable GetContactsContactInfo()
        {
            // SqlCommand cmdSelect = new SqlCommand("SELECT firstName+' '+lastName as Caller, businessPhone as Phone, companyId as Company FROM ccContacts", m_Connection);
            //Ask abhiskek about sp
           string sp = "GetContactContactInfos";
           return this.Factory.ExecuteTable(sp);
        }

        public DataTable GetCallHistory()
        {
            //SqlCommand cmdSelect = new SqlCommand("SELECT cc.firstName+' '+ cc.lastName as Name, cl.callDate as Date, cl.notes, cp.name as Company, cm.description as Via FROM ccCallsLog cl INNER JOIN ddlCompany cp ON cp.id= cl.companyId Inner JOIN  ccContacts cc ON cc.userId = cl.userId INNER JOIN ddlCommunicationMedium cm ON cm.id = cl.communicationId", m_Connection);
            string sp= "getCallHistory";
            return this.Factory.ExecuteTable(sp);
        }

        public int Insert(int userId, int companyId, int contactId, int receiverId, int projectId, int communicationId, int solutionId, DateTime callDate,DateTime callStartTime,  DateTime callEndTime, string subjectDes, string callStatus, DateTime followupDate, bool serviceCall, string priority, bool billable, string notes, bool visibleToOther)
        {
            int nRtn = -1;
          string sql = "INSERT INTO ccCallsLog" +
                "(userId, companyId, contactId, receiverID, projectId, communicationId, solutionId, callDate, callStartTime, callEndTime, subjectDes, callStatus, followupDate, serviceCall, priority, billable, notes, visibleToOther)" +
            "VALUES(@userId, @companyId, @contactId, @receiverID, @projectId, @communicationId, @solutionId, @callDate, @callStartTime, @callEndTime, @subjectDes, @callStatus, @followupDate, @serviceCall, @priority, @billable, @notes, @visibleToOther)" +
            "SELECT @ID =@@IDENTITY";

            using (var cmd = this.Factory.GetCommand(sql))
            {
                this.Factory.AddParameter(cmd, "@userId", SqlDbType.Int, 10, userId);
                this.Factory.AddParameter(cmd, "@receiverId", SqlDbType.Int, 10, receiverId);
                this.Factory.AddParameter(cmd, "@projectId", SqlDbType.Int, 10, projectId);
                this.Factory.AddParameter(cmd, "@companyId", SqlDbType.Int, 10, companyId);
                this.Factory.AddParameter(cmd, "@contactId", SqlDbType.Int, 10, contactId);
                this.Factory.AddParameter(cmd, "@communicationId", SqlDbType.Int, 10, communicationId);
                this.Factory.AddParameter(cmd, "@solutionId", SqlDbType.Int, 10, solutionId);
                this.Factory.AddParameter(cmd, "@callDate", SqlDbType.SmallDateTime,0,callDate);
                this.Factory.AddParameter(cmd, "@callStartTime", SqlDbType.SmallDateTime,0,callStartTime);
                this.Factory.AddParameter(cmd, "@callEndTime", SqlDbType.SmallDateTime,0,callEndTime);
                this.Factory.AddParameter(cmd, "@visibleToOthers", SqlDbType.Bit, 0, visibleToOther);
                this.Factory.AddParameter(cmd, "@followupDate", SqlDbType.SmallDateTime,0,followupDate);
                this.Factory.AddParameter(cmd, "@serviceCall", SqlDbType.Bit,10,serviceCall);
                this.Factory.AddParameter(cmd, "@priority", SqlDbType.NVarChar, 10, priority);
                this.Factory.AddParameter(cmd, "@billable", SqlDbType.Bit,10,billable);
                this.Factory.AddParameter(cmd, "@notes", SqlDbType.VarChar, 1000, notes);
                this.Factory.AddParameter(cmd, "@subjectDes", SqlDbType.NVarChar, 1000, subjectDes);
                this.Factory.AddParameter(cmd, "@callStatus", SqlDbType.VarChar, 1000, callStatus);
               // this.Factory.AddParameter(cmd, "@Id", SqlDbType.Int, 10,id);
                this.Factory.ExecuteNonQuery(cmd);

            }
           
            //// returning the data inserted in the data by its new ID
            //cmdInsert.Parameters.Add("@ID", SqlDbType.Int);
            //cmdInsert.Parameters["@ID"].Direction = ParameterDirection.Output;
          
            return nRtn; //retruning the data stored in the table
        }



        //public void Delete(int nCallHistoryId) //delete the row of data using the id passed to the function
        //{
        //   string sql= "DELETE FROM scratchPad " +
        //        "WHERE ID = @ID ";

        //    using (var cmd = this.Factory.GetCommand(sql))
        //    {
                      
        //        this.Factory.AddParameter(cmd, "@ID", SqlDbType.Int, 4,nCallHistoryId);
        //        this.Factory.ExecuteNonQuery(cmd);
        //    }
        //}

        public void DeleteAll() //delete all the rows in the data.
        {
            string sql = "DELETE FROM scratchPad ";
           this.Factory.ExecuteTable(sql);
    }

      
    }
}

